package com.wq.gateway.service.domain;

import com.wq.gateway.service.common.enums.ResultEnum;
import lombok.Data;

@Data
public class Result<T> {

    private int code;

    private String msg;

    private T data;

    private Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data);
    }

    public static <T> Result<T> success(String msg, T data) {
        return new Result<T>(ResultEnum.SUCCESS.getCode(), msg,data);
    }

    public static <T> Result<T> failed(String msg) {
        return new Result<T>(ResultEnum.FAILED.getCode(), msg, null);
    }

    public static <T> Result<T> failed(int code, String msg) {
        return new Result<T>(code, msg, null);
    }

}

